package com.kky.pp.activity.wlm

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.RecyclerView
import com.kky.pp.R
import com.kky.pp.bean.WhoLikeMeListBean
import com.gyf.immersionbar.ImmersionBar
import com.custom.base.mvp.MVPBaseFragment
import com.google.gson.Gson
import com.scwang.smart.refresh.layout.SmartRefreshLayout
import com.custom.base.base.SDBaseEvent
import com.kky.pp.databinding.FragmentTwoBinding
import io.rong.imkit.event.EnumEventTag
import io.rong.imkit.utils.JsonUtils
import io.rong.imkit.utils.StatusBarUtil
import org.json.JSONObject


class WhoLikeMeFragment : MVPBaseFragment<WhoLikeMeContract.View, WhoLikeMePresenter,FragmentTwoBinding>(FragmentTwoBinding::inflate), WhoLikeMeContract.View {

    override fun bindLayout(): Int {
        return R.layout.fragment_two
    }

    override fun initView(view: View) {
        fragmentViewBinding?.conLikeMeFragMain?.setPadding(0, StatusBarUtil.getStatusBarHeight(mActivity),0,0)
    }
    override fun onEventMainThread(event: SDBaseEvent) {
        when (EnumEventTag.valueOf(event.tagInt)) {
            EnumEventTag.WLM_LIKE_SWIPED->{
                mPresenter?.removeData(event.data.toString().toInt())
            }
            EnumEventTag.WLM_DISLIKE_SWIPED->{
                mPresenter?.removeData(event.data.toString().toInt())
            }
            EnumEventTag.WLM_REFRESH->{
                mPresenter?.getData()
            }
            EnumEventTag.WLM_REFRESH_ITEM->{
                if (JsonUtils.isJSON(event.data.toString())) {
                    val jsonObject = JSONObject(event.data.toString())
                    mPresenter?.refreshItem(
                        jsonObject.getString("userCode"),
                        jsonObject.getInt("online")
                    )
                }
            }
            EnumEventTag.WLM_ADD_ITEM->{
                if (JsonUtils.isJSON(event.data.toString())) {
                    val jsonObject = JSONObject(event.data.toString())
                    val bean = Gson().fromJson(
                        jsonObject.getString("wlmUserInfo"),
                        WhoLikeMeListBean::class.java
                    )
                    mPresenter?.addItem(bean)
                }
            }
            else -> {}
        }
    }

    override fun onResume() {
        super.onResume()
        ImmersionBar.with(mActivity).statusBarDarkFont(false).init()
    }

    override fun onHiddenChanged(hidden: Boolean) {
        super.onHiddenChanged(hidden)
        if (!hidden){
//            ImmersionBar.with(this)
//                .statusBarColor("#ffffff")
//                .init()
        }
    }

//    override val titleWlm: TextView
//        get() = title_wlm

    override val txtLikeMeFragEdit: TextView
        get() = fragmentViewBinding?.txtLikeMeFragEdit!!
    override val conLikeMeFragEmpty: ConstraintLayout
        get() = fragmentViewBinding?.conLikeMeFragEmpty!!
    override val rvLikeMeList: RecyclerView
        get() = fragmentViewBinding?.rvLikeMeList!!
    override val refreshLayoutLikeMeFrag: SmartRefreshLayout
        get() = fragmentViewBinding?.refreshLayoutLikeMeFrag!!
    override val txtLikeMeFragPremiumUnlock: TextView
        get() = fragmentViewBinding?.txtLikeMeFragPremiumUnlock!!
    override val txtLikeMeFragSize: TextView
        get() = fragmentViewBinding?.txtLikeMeFragSize!!
}